const path = require("path");

const {
  getAppGoodsList,
  getGoodsDetail,
  gainHotAndNewGoods,
} = require("../service/appGoods.service");
class GoodsController {
  // 获取商品列表
  async getAppGoodsList(ctx, next) {
    // 获取pageNum和pageSize,goodsName,category
    const {
      pageNum = 1,
      pageSize = 10,
      goodsName = "",
      category = "",
    } = ctx.query;
    const res = await getAppGoodsList({
      pageNum,
      pageSize,
      goodsName,
      category,
    });
    ctx.response.body = {
      code: "10010",
      message: "获取商品列表成功",
      data: res,
    };
    await next();
  }

  // 获取商品详情
  async getAppGoodsDetail(ctx, next) {
    const { id } = ctx.query;
    const res = await getGoodsDetail(id);
    ctx.response.body = {
      code: "10010",
      message: "获取商品详情成功",
      data: res,
    };
    await next();
  }

  // 获取热点商品以及新品
  async getHotAndNewGoods(ctx, next) {
    const { isHot, isNew } = ctx.request.query;
    const res = await gainHotAndNewGoods({ isHot, isNew });

    ctx.response.body = {
      code: "10010",
      message: "获取商品成功",
      data: res,
    };
    await next();
  }
}

module.exports = new GoodsController();
